
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<form id="goodsAdd"  method="post"  >
    <table align="center" width="700px;" cellspacing="30" >
        <tr>
            <td>
                <label for="name">名称:</label>
                <input class="easyui-validatebox" type="text" id="name" name="name" data-options="required:true" />
            </td>
            <%--<td><input class = "easyui-filebox" name = 'pic' style = "width:153px" data-options = "required:true,prompt:'选择上传图片',buttonText:' 选 择 '">--%>
            <%--<input type = 'text' id = "Item" name = 'item' style = "display:none;"></td>--%>
        </tr>
        <tr>
            <td><label for="code">编号:</label>
                <input class="easyui-validatebox" type="text" id="code" name="code" data-options="required:true" />
            </td>
            <td> <label for="categoryId">分类:</label>
                <input id="categoryId" class="easyui-combobox" name="categoryId"
                       data-options="valueField:'id',textField:'name',method:'get',url:'api/goods/category/findAll',required:true" />
            </td>
        </tr>
        <tr>
            <td><label for="spec">规格:</label>
                <input class="easyui-validatebox" type="text" id="spec" name="spec"  />
            </td>
            <td>  <label for="unitId">单位:</label>
                <input id="unitId" class="easyui-combobox" name="unitId"
                       data-options="valueField:'id',textField:'name',method:'get',url:'api/goods/unit',required:true" />
            </td>

        </tr>
        <tr>
            <td> <label for="barCode">条形码:</label>
                <input class="easyui-validatebox" type="text" id="barCode" name="barCode"  />
            </td>
            <td> <label for="salePrice">零售价:</label>
                <input class="easyui-validatebox" type="text" id="salePrice" name="salePrice" data-options="required:true"/>
            </td>

        </tr>
        <tr>
            <td><label for="brandId">品牌:</label>
                <input id="brandId" class="easyui-combobox" name="brandId"
                       data-options="valueField:'id',textField:'name',method:'get',url:'api/goods/brand/findAll'" />
            </td>
            <td><label for="purchasePrice">进价:</label>
                <input class="easyui-validatebox" type="text" id="purchasePrice" name="purchasePrice"  />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label for="memo">备注:</label>
                <input class="easyui-validatebox" type="text" id="memo" name="memo" style="width: 510px"   />
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"  onclick="AddsubmitForm()">保存</a>
                <a class="easyui-linkbutton" data-options="iconCls:'icon-no'"  style="margin-left: 60px;" onclick="EditclearForm()">重置</a>
            </td>
        </tr>
    </table>
</form>
<script>
    function EditclearForm(){
        $('#goodsAdd').form('clear');
    }
    function AddsubmitForm(){
        $('#goodsAdd').form('submit', {
            url: 'api/goods/good',
            onSubmit: function () {        //表单提交前的回调函数
                var isValid = $(this).form('validate');//验证表单中的一些控件的值是否填写正确，比如某些文本框中的内容必须是数字
                if (!isValid) {
                }
                return isValid; // 如果验证不通过，返回false终止表单提交
            },
            success: function (data) {  //表单提交成功后的回调函数，里面参数data是我们调用/BasicClass/ModifyClassInfo方法的返回值。
                var jsonData=(JSON.parse(data)) ;
                if (jsonData.data > 0) {
                    $.messager.show({
                        title: '提示消息',
                        msg: jsonData.message,
                        showType: 'show',
                        timeout: 1000,
                        style: {
                            right: '',
                            bottom: ''
                        }
                    });
                    $('#goodsAddDialog').dialog('close');
                    $('#goodsGrid').datagrid({
                        url:'api/goods/good/list',
                        queryParams:{page:"1",rows:"10"}
                    });
                } else {
                    $.messager.alert('提示信息',jsonData.message, 'warning');
                    $('#goodsAdd').form('clear');
                }
            }
        });

    }
</script>

